<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>05.form_fields | KnockOut</title>
  <script src="../assets/knockout-3.5.1.js"></script>
</head>
<body>

  <ul data-bind="foreach: places">
    <!-- 显示内容用 text，绑定事件用 event -->
    <li data-bind="text: $data, event: { mouseover: $parent.logMouseOver }"> </li>
  </ul>
  <p>你感兴趣的是: <span data-bind="text: lastInterest"> </span></p>
  
  <script type="text/javascript">
    function MyViewModel() {
      var self = this;
      self.lastInterest = ko.observable();
      self.places = ko.observableArray(['北京', '青岛', '台北']);

      // 当前项作为参数传入回调函数
      self.logMouseOver = function(place) {
        self.lastInterest(place);
      }
    }

    ko.applyBindings(new MyViewModel());
  </script>
    
</body>
</html>
